<?php

/**
 * Framework_Module_People
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Modules
 * @filesource
 */

/**
 * Framework_Module_People
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Modules
 */
class Framework_Module_People extends Framework_Module
{
		
	/**
	 * $navParts
	 *
	 * A copy of Framework_Request's $requestParts
	 *
	 * @var 	array 	$data 	Navigation parts seen in the URL
	 * @todo 	This needs to be removed and set is the module super class as a reference
	 * @see 	Framework_Request
	 */
	private $navParts;
	
	
		
	/**
     * __construct
     *
     * Initializes the module: sets the default presenter, the allowed
     * conrollers, and the allowed events
     *
     * @access 		public
     * @return 		void
     */
	public function __construct()
	{
		parent::__construct();
		if (Framework::$request->isAjax()) {
			$this->presenter = 'Module';
		 } else {
			$this->presenter = 'Smarty';
		 }
		 
		$this->tplFile = 'People.tpl';
		// Set outer template
		$this->pageTemplateFile = 'ProfilePage.tpl';
			
		// Nav Parts
		$this->navParts = Framework::$request->requestParts;
			
		// Valid Controllers
		$this->controllers[] = 'Peopletab';
		
		 //Caching
		 $this->isCacheable = true;
		 $this->cacheHandlerClass = 'Module';

		 
	}

	/**
     * __default
     *
     * Gets owner's friends, watching, or watched-by list
     *
     * @access 		public
     * @return 		mixed 		boolean true on success, PEAR_Error on failure
     */
	public function __default()
	{
		// Get the page owner 
		$owner = Framework_Owner::singleton();
		
		$cacheHandler = $this->getCacheHandler();

		// Make Navigation
		$navigator = new Framework_Navigator('/'.$owner->userName.'/People', 'peopleNavList');
		$navigator->setItem('friendsListItem','/friends','friends');
		$navigator->setItem('watchingListItem','/watching','watching');
		$navigator->setItem('watchedByListItem','/watchedBy','watchedBy');
		 
		switch ($this->navParts[0]) {
			case 'friends':
			$navigator->setActive('friendsListItem');
			break;
			
			case 'watching':
			$navigator->setActive('watchingListItem');
			break;
			
			case 'watchedBy':
			$navigator->setActive('watchedByListItem');
			break;
			
			default:
			$navigator->setActive('friendsListItem');
			break;
		}
		
		

		$people = $owner->getPeople($this->navParts[0], 15, 'page', $cacheHandler);
		 
		// Set data
		if(!PEAR::isError($people)) {
			$peopleData = $people->getData();
			
			if (!PEAR::isError($peopleData) && count($peopleData)) {
				$this->setData('people', $peopleData);
				$this->setData('pager', $people->getPager());
			} else {
				$this->setData('noResults', 'No people to display!');
			}
		} else {
			return $people;
		}
		 
		$this->setData('peopleNavList',$navigator->getNavigation());

		return true;

	}


}

?>